package logic

import (
	"context"
	"house_srv/models/mysql"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *house.UserListRequest) (*house.UserListResponse, error) {
	// todo: add your logic here and delete this line
	var user []mysql.User
	mysql.Db.Model(&user).Order("status").Limit(10).Find(&user)
	var slice []*house.UserList
	for _, v := range user {
		list := house.UserList{
			Mobile:   v.Mobile,
			RealName: v.RealName,
			IDCord:   v.IDCord,
			Front:    v.Front,
			Back:     v.Back,
			Status:   v.Status,
			UserId:   int64(v.ID),
		}
		slice = append(slice, &list)
	}
	return &house.UserListResponse{
		List: slice,
	}, nil
}
